package com.example.spark.controller;

import com.example.spark.entity.Activity;
import com.example.spark.entity.result.CommonResult;
import com.example.spark.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@CrossOrigin
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    //根据类型查询活动
    @GetMapping("selectActivity/{type}")
    public CommonResult selectByType(@PathVariable int type) {

        return activityService.selectByType(type);
    }

    //添加活动
    @PostMapping("addActivity")
    public CommonResult addActivity(@RequestBody Activity activity) {

        return activityService.addActivity(activity);
    }

    //删除活动
    @DeleteMapping("deleteActivity/{id}")
    public CommonResult deleteActivity(@PathVariable Long id) {

        return activityService.deleteActivity(id);
    }

    //修改活动
    @PutMapping("updateActivity")
    public CommonResult updateActivity(@RequestBody Activity activity) {

        return activityService.updateActivity(activity);
    }

    //图片
    @PutMapping("activityPhotos/{id}")
    public  CommonResult addPhoto(@RequestParam MultipartFile file, @PathVariable Long id) throws IOException {

        return activityService.addPhoto(file,id);
    }

}
